package com.uzai.console.web.jd;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.uzai.console.annotation.SystemLogType;
import com.uzai.console.dto.jd.jdorder.JdOrderApiDownLoadDto;
import com.uzai.console.dto.jd.jdtokenapi.JdTokenApiIdDto;
import com.uzai.console.dto.jd.jdtokenapi.JdTokenApiInfoDto;
import com.uzai.console.dto.jd.jdtokenapi.JdTokenApiQuery;
import com.uzai.console.dto.jd.jdtokenapi.JdTokenCheckTokenDto;
import com.uzai.console.dto.tb.tborder.TbOrderApiDownLoadDto;
import com.uzai.console.enums.OperationTypeEnum;
import com.uzai.console.enums.SystemModelEnum;
import com.uzai.console.service.jd.JdOrderService;
import com.uzai.console.service.jd.JdTokenApiService;
import com.uzai.console.service.tb.tborder.TbOrderService;
import com.uzai.console.vo.jd.jdtokenapi.JdTokenApiInfoVo;
import com.uzai.console.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 产品
 * @author liuqi
 * @date 2021年08月16日 15:11
 */
@Api(value = "拉取订单京东联盟",tags = "京东|拉取订单京东联盟")
@ApiSort(10)
@RestController
public class JdTokenApiController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(JdTokenApiController.class);

    @Autowired
    private JdTokenApiService jdTokenApiApiService;
    @Autowired
    private JdOrderService jdOrderService;

    @ApiOperation(value = "分页查询拉取订单京东联盟列表", notes = "分页查询拉取订单京东联盟列表", response = JdTokenApiInfoVo.class)
    @ApiOperationSupport(order = 1)
    @PostMapping("/jdTokenApiApi/findJdTokenApiList")
    public Object findJdTokenApiList(@RequestBody JdTokenApiQuery jdTokenApiApiQuery){
        return jdTokenApiApiService.findJdTokenApiList(jdTokenApiApiQuery);
    }

    @ApiOperation(value = "查询拉取订单京东联盟详情", notes = "查询拉取订单京东联盟详情", response = JdTokenApiInfoVo.class)
    @ApiOperationSupport(order = 2)
    @PostMapping("/jdTokenApiApi/findJdTokenApiInfo")
    public Object findJdTokenApiInfo(@RequestBody JdTokenApiIdDto jdTokenApiApiIdDto){
        return jdTokenApiApiService.findJdTokenApiInfo(jdTokenApiApiIdDto);
    }

    @SystemLogType(model = SystemModelEnum.JdTokenApi, type = OperationTypeEnum.ADD)
    @ApiOperation(value = "添加拉取订单京东联盟", notes = "添加拉取订单京东联盟")
    @ApiOperationSupport(order = 3)
    @PostMapping("/jdTokenApiApi/addToken")
    public Object addJdTokenApi(@RequestBody JdTokenApiInfoDto jdTokenApiApiInfoDto){
        jdTokenApiApiService.addJdTokenApi(jdTokenApiApiInfoDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.JdTokenApi, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "修改拉取订单京东联盟", notes = "修改拉取订单京东联盟")
    @ApiOperationSupport(order = 4)
    @PostMapping("/jdTokenApiApi/updateToken")
    public Object updateJdTokenApi(@RequestBody JdTokenApiInfoDto jdTokenApiApiInfoDto){
        jdTokenApiApiService.updateJdTokenApi(jdTokenApiApiInfoDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.JdTokenApi, type = OperationTypeEnum.DELETE)
    @ApiOperation(value = "删除拉取订单京东联盟", notes = "删除拉取订单京东联盟")
    @ApiOperationSupport(order = 5)
    @PostMapping("/jdTokenApiApi/deleteToken")
    public Object deleteToken(@RequestBody JdTokenApiIdDto jdTokenApiApiInfoDto){
        jdTokenApiApiService.deleteToken(jdTokenApiApiInfoDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.JdTokenApi, type = OperationTypeEnum.DOWNLOAD)
    @ApiOperation(value = "通过API手动下载京东订单", notes = "通过API手动下载京东订单")
    @ApiOperationSupport(order = 6)
    @PostMapping("/jdTokenApiApi/downloadOrderByApi")
    public Object downloadOrderByApi(@RequestBody JdOrderApiDownLoadDto jdOrderApiDownLoadDto){
        jdOrderService.downloadOrderApi(jdOrderApiDownLoadDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.JdTokenApi, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "检测京东联盟的token是否合法", notes = "检测京东联盟的token是否合法", response = Boolean.class)
    @ApiOperationSupport(order = 7)
    @PostMapping("/jdTokenApiApi/checkToken")
    public Object checkToken(@RequestBody JdTokenCheckTokenDto jdTokenCheckTokenDto){
        return jdTokenApiApiService.checkToken(jdTokenCheckTokenDto);
    }
}
